/* 2017/05/05 */
package org.sample.springboot.converter.print;

import java.lang.reflect.Field;
import org.sample.springboot.converter.SingleFieldConverter;

public class PrintConverter extends SingleFieldConverter {

	@Override
	protected boolean isScanTargetField(Field field) {
		if (!String.class.isAssignableFrom(field.getType())) {
			return false;
		}

		Print[] annotations = field.getAnnotationsByType(Print.class);
		return annotations.length > 0;
	}

	@Override
	protected boolean isConvertTargetField(Field field) {
		if (!String.class.isAssignableFrom(field.getType())) {
			return false;
		}
		return true;
	}

	@Override
	protected void convertTargetField(Field field, Object object, Object value) {
		if (value == null) {
			System.out.println("Value of field " + field.getName() + ": null.");
		} else {
			System.out.println("Value of field " + field.getName() + ": \"" + (String) value + "\".");
		}
	}

}
